pacman::p_load(sf, spdep, GWmodel, SpatialML, tmap, rsample, Metrics, tidyverse)Hands-on Ex 8
Geographically Weighted Predictive Models
1. Overview
Geospatial predictive modeling is based on the understanding that events or phenomena are not randomly or uniformly distributed across space. Instead, their occurrences are influenced by a variety of geospatial factors such as infrastructure, sociocultural dynamics, topography, and environmental conditions. These factors constrain and shape where events are likely to occur. Geospatial predictive modeling aims to capture these influences by analysing the spatial correlations between historical event locations and the environmental variables that represent these constraints and influences.
In this exercise, we will undertake the following steps to build a predictive model using the geographical random forest method:
- Prepare Train and Test Datasets using appropriate data sampling methods.
- Calibrate Predictive Models using both geospatial statistical learning and machine learning methods.
- Compare and Select the Best Model which provides the most accurate predictions.
- Predict Future Outcomes using the best-calibrated model.
The following R packages will be used in geospatial predictive modelling.
2. Importing & Preparing Data
mdata <- read_rds("data/mdata.rds")any(duplicated(mdata))[1] TRUE
set.seed(1234)
for (i in 1:nrow(mdata)) {
coords <- st_coordinates(mdata[i, ]) # Extract current point coordinates
jittered_coords <- coords + runif(n = 1, min = -0.1, max = 0.1)
mdata[i,]$geometry <- st_sfc(st_point(c(jittered_coords), dim = "XY"), crs = 3414)
}any(duplicated(mdata))[1] FALSE
tmap_mode('view')tmap mode set to interactive viewing
tm_shape(mdata) +
tm_dots()